<?php
// +----------------------------------------------------------------------
// | Author: fulei  Email:365581323@qq.com
// +----------------------------------------------------------------------
namespace app\back\controller;
use think\Controller;
use think\Request;
use think\Db;
use app\admin\model\User;
class Member extends Common
{   /*会员列表*/
    public function member_list()
    {   
        
         $userList = Db::name('user_info')->where(['member_type'=>'1','user_audit'=>'1'])->paginate(5,false);
         $page = $userList->render();
         $this->assign('userList',$userList);
         $this->assign('page',$page);
          return $this->fetch('Member/member_list');
    }

    //用户启用-禁用的操作
    public function member_stop()
    {   
        $uid = input('uid');
        $userFlag = input('userFlag');
        $result =Db::name('user_info')->where(['uid'=>$uid])->setField('userFlag',$userFlag); 
        if($result){
         return json(['state' => '1', 'msg' => '操作成功!']);
        }else{
         return json(['state' => '0', 'msg' => '操作失败再试试!']);
        }
    } 
    //会员审核列表
    public function  member_check(){
         $userList = Db::name('user_info')->where(['user_audit'=>'-1','member_type'=>'1'])->paginate(5,false);
        // print_r($userList);die;
         $page = $userList->render();
         $this->assign('userList',$userList);
         $this->assign('page',$page);
          return $this->fetch('Member/member_check');
    }
    //用户审核的操作
    public function audit()
    {   
        $uid = input('uid');
        $user_audit = input('user_audit');
        $result =Db::name('user_info')->where(['uid'=>$uid])->setField('user_audit',$user_audit); 
        if($result){
         return json(['state' => '1', 'msg' => '审核操作成功!']);
        }else{
         return json(['state' => '0', 'msg' => '审核操作失败再试试!']);
        }
    } 
    //用户注销列表
    public function member_cancel(){
           $pagenumber = 5;//默认分页条数
         $userList = Db::name('user_forbidden')->paginate($pagenumber,false);
         if($userList->toArray())
        {
            $userList->toArray();
            foreach($userList as $k=>$v){
              $userName=Db::name('user_info')->where(['uid'=>$v['uid']])->find();
              //$userList[$k]['nickname']=$userName['nickname'];
                 $data = array();
                 $data = $v;
                // print_r($data);
                 $data['nickname'] =$userName['nickname'];
                 $data['userPhone'] =$userName['userPhone'];
                 $userList->offsetSet($k,$data);
            } 
        }
         $page = $userList->render();
         $this->assign('userList',$userList);
         $this->assign('page',$page);
          return $this->fetch('Member/member_cancel');
    }
    //用户等级提升
    public function member_upgrade(){
          $uid = input('uid');
        $member_type = input('member_type');
        $result =Db::name('user_info')->where(['uid'=>$uid,'member_type'=>'1'])->setField('member_type',$member_type); 
        if($result){
         return json(['state' => '1', 'msg' => '操作成功!']);
        }else{
         return json(['state' => '0', 'msg' => '操作失败再试试!']);
        }
    }
    //添加用户
    //添加用户页面展示
    public function member_add(){
       return $this->fetch('Member/member_add');
    }
    public function memberto(){
        $data=input('post.');//获取所有的值
         $filephoto = request()->file('img');//领队头像
       // print_r(json($file));
        $file1 = request()->file('img1');
       // print_r($file1);die;
        $file2 = request()->file('img2');
        $file3 = request()->file('img3');
        $file4 = request()->file('img4');
        $file5 = request()->file('img5');
        if(!empty($filephoto)){
            $rs=$this->uploadImg($filephoto);
            if($rs){
               $userPhoto=$rs;//领队头像
            }else{
                $userPhoto="";
                return json(['state' => '0', 'msg' => '用户头像上传失败']);
            }
        }
        if(!empty($file1)){
            $rs=$this->uploadImg($file1);
            if($rs){
               $userImg1=$rs;//背景图1
            }else{
                return json(['state' => '0', 'msg' => '背景图1上传失败']);
            }
        }
          if(!empty($file2)){
            $rs=$this->uploadImg($file2);
            if($rs){
               $userImg2=$rs;//背景图2
            }else{
                return json(['state' => '0', 'msg' => '背景图2上传失败']);
            }
        }
          if(!empty($file3)){
            $rs=$this->uploadImg($file3);
            if($rs){
               $userImg3=$rs;//背景图2
            }else{
                return json(['state' => '0', 'msg' => '背景图3上传失败']);
            }
        }
          if(!empty($file4)){
            $rs=$this->uploadImg($file4);
            if($rs){
               $userImg4=$rs;//背景图2
            }else{
                return json(['state' => '0', 'msg' => '背景图4上传失败']);
            }
        }
          if(!empty($file5)){
            $rs=$this->uploadImg($file5);
            if($rs){
               $userImg5=$rs;//背景图2
            }else{
                return json(['state' => '0', 'msg' => '背景图5上传失败']);
            }
        }
        $data['userPhoto']=$userPhoto;$data['userImg1']=$userImg1;
        $data['userImg2']=$userImg2;
        $add = Db::name('user_info')->insert($data);
        if($add){
             return json(['state' => '1', 'msg' => '添加成功']);
        }else{
             return json(['state' => '0', 'msg' => '添加失败再试试']);
        }
    }
}